package com.itany.book.controller;

import ch.qos.logback.classic.pattern.RelativeTimeConverter;
import com.github.pagehelper.PageInfo;
import com.itany.book.pojo.Book;
import com.itany.book.service.BookService;
import com.itany.book.vo.ResponseResult;
import org.apache.shiro.crypto.hash.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2019/12/25 8:17
 * Describe:
 * version:1.0
 */

@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    @RequestMapping("/findById")
    @ResponseBody
    public ResponseResult findById(Integer id){
        Book book = bookService.findById(id);
        System.out.println("----------");
        System.out.println(book);
        return ResponseResult.success(book);
    }

    @RequestMapping("/findAll")
    @ResponseBody
    public Map findAll(Integer page,
                                  Integer rows,
                                  String bookname,
                                  String isbn,
                                  Integer pressid,
                                  Integer supplierid){
        System.out.println("-------------------------");
        System.out.println(rows);
        System.out.println(bookname);
        System.out.println(isbn);
        System.out.println(pressid);
        System.out.println(supplierid);
        PageInfo<Book> info = bookService.findAll(page, rows, bookname, isbn, pressid, supplierid );
        Map map = new HashMap<>();
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;

    }
}
